package com.psp.park.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.park.controller.res.*;
import com.psp.park.controller.res.bean.*;
import com.psp.park.controller.springmvc.req.*;

/**
 * 合作登记记录-相关接口
 **/
@Controller
@RequestMapping(value = "/park/cooperation", produces = "application/json")
public class SCooperationController {
	@Autowired
	com.psp.park.controller.CooperationController cooperationController;

	/**
	 * 获取合作商家列表
	 **/
	@RequestMapping("/v1/list")
	@ResponseBody
	public ListResult<RCooperationBean> list(@Validated GetCooperationListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RCooperationBean> res = new ListResult<RCooperationBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return cooperationController.list(param, request, response);
	}

	/**
	 * 合作登记
	 **/
	@RequestMapping("/v1/checkIn")
	@ResponseBody
	public ObjectResult<RUserBean> checkIn(@Validated CompanyCheckInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RUserBean> res = new ObjectResult<RUserBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return cooperationController.checkIn(param, request, response);
	}

	/**
	 * 合作登记
	 **/
	@RequestMapping("/v1/edit")
	@ResponseBody
	public BaseResult edit(@Validated EditCompanyCheckInParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return cooperationController.edit(param, request, response);
	}

	/**
	 * 合作登记
	 **/
	@RequestMapping("/v1/getNum")
	@ResponseBody
	public ObjectResult<Integer> getNum(HttpServletRequest request, HttpServletResponse response) {

		return cooperationController.getNum(request, response);
	}

	/**
	 * 合作登记
	 **/
	@RequestMapping("/v1/del")
	@ResponseBody
	public BaseResult del(@Validated DelCooperationParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return cooperationController.del(param, request, response);
	}
}
